#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Import this to put your site in maintenance mode, denying all requests.

I have not tested this module yet.
"""

import cherrypy

# html = None
# title = u"Site in maintenance"
msg = """This website is currently down for maintenance.
Please try again in a few minutes."""

def die():
    cherrypy.config.update({'tools.sessions.on' : False}) # prevent error
    """cherrypy.response.status = 503
    if html is None:
        cherrypy.response.body = [u'''<html><title>%s</title>
                <body><h1>%s</h1>
                <p>%s</p>
                </body>
                </html>''' % (title, title, msg)]
    else:
        cherrypy.response.body = [html]
    """
    raise cherrypy.HTTPError(503, msg)  # 503 == Service Unavailable

cherrypy.tools.maintain = cherrypy.Tool('before_handler', die, priority=0)
cherrypy.config.update({'tools.maintain.on': True})
